package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.CourseApply;
import com.example.fitnessservice.module.pojo.Result;
import com.example.fitnessservice.service.CoachApproveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author feng
 * @version 1.0
 * @&#064;description: 教练申请和审批
 * @&#064;date 2022/11/27 21:59
 */
@RestController
@RequestMapping("approve")
public class CoachApproveController {
    @Autowired
    CoachApproveService coachApproveService;
    /*
    教练查询所有申请
     */
    @GetMapping("/{coachId}")
    public Result getAllApply(@PathVariable("coachId") Integer coachId){
        Result result = new Result();
        List<CourseApply> courseApplyList= coachApproveService.getAllApppy(coachId);
        result.setCode(200);

        if (courseApplyList.size() > 0) {
            result.setMsg("查到了申请");
            result.setData(courseApplyList);
        }
        return result;
    }
    /*
    教练审批课程申请
     */
    @PutMapping("/{coachId}/{userId}/{courseId}/{passIf}")
    public Result approve(@PathVariable("coachId") Integer coachId,
                          @PathVariable("userId") Integer userId,
                          @PathVariable("courseId")Integer courseId,
                          @PathVariable("passIf") Integer passIf
    ){
        Result result = new Result();
        if (coachApproveService.approve(coachId, userId, courseId, passIf)) {
            result.setMsg("已经审批了");
            result.setCode(200);

        } else {
            result.setMsg("审批失败了");
            result.setCode(500);
        }
        return result;
    }

    /*
    教练操作上课
     */
    @PutMapping("/take/{courseId}/{courseCampIf}")
    public Result takeCourse(@PathVariable Integer courseId,
                             @PathVariable Integer courseCampIf) {
        Result result = new Result();
        if (coachApproveService.takeCourse(courseId, courseCampIf)) {
            result.setMsg("开始上课");
            result.setCode(200);
        }
        return result;
    }
    /*教练操作完成订单

     */
    @PutMapping("/finish/{courseId}/{courseCampIf}")
    public Result finishCourse(@PathVariable Integer courseId,
                               @PathVariable Integer courseCampIf) {
        Result result = new Result();
        if (coachApproveService.finishCourse(courseId, courseCampIf)) {
            result.setMsg("订单已完成");
            result.setCode(200);
        } else {
            result.setMsg("订单已失败");
            result.setCode(500);
        }
        return result;
    }
}
